package com.techsoul.module.pms.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.accounting.pojo.param.AccApSkuMonthlySettlementSearchParam;
import com.techsoul.module.basic.pojo.param.SuspiciousItemSaveParam;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialDeliveryLineSaveParam;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialReceiptLineSaveParam;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialReceiptLineSearchParam;
import com.techsoul.module.pms.service.ITbWmsMaterialReceiptLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 入库计划明细 Controller
 *
 * @author liuen
 * @date 2022-01-25
 */
@Api(tags = "入库计划明细")
@RestController
@RequestMapping("/web/tbWmsMaterialReceiptLine")
public class TbWmsMaterialReceiptLineController {

    @Autowired
    private Result result;
    
    @Autowired
    private ITbWmsMaterialReceiptLineService service;

    @ApiOperation("新增")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody TbWmsMaterialReceiptLineSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("移入可疑")
    @Log(title = "移入可疑", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:update')")
    @PostMapping("/moveToSuspicious")
    public Result moveToSuspicious(@Valid @RequestBody TbWmsMaterialReceiptLineSaveParam params) {
        return result.success(this.service.moveToSuspicious(params));
    }
    @ApiOperation("确认")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:update')")
    @PostMapping("/confirm/{id}")
    public Result confirm(@PathVariable("id") String id) {
        return result.success(this.service.confirm(id));
    }
    @ApiOperation("批量删除（多个用逗号隔开）")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:update')")
    @PutMapping
    public Result update(@Valid @RequestBody TbWmsMaterialReceiptLineSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {

        return result.success(this.service.findById(id));
    }
    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:search')")
    @GetMapping("/getOrderDetail/{id}")
    public Result getWithDeliverysAndArs(@PathVariable("id") String id) {

        return result.success(this.service.getWithDeliverysAndArs(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody TbWmsMaterialReceiptLineSearchParam params) {
        return result.success(this.service.findAll(params));
    }
    @ApiOperation("批量生成入库结算")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialDeliveryLine:generateArForRecept')")
    @PostMapping("/generateArForRecept/{ids}")
    public Result generateArForRecept(@PathVariable String[] ids) {
        return result.success(this.service.generateArForReceipt(Arrays.asList(ids)));
    }
    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialReceiptLine:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody TbWmsMaterialReceiptLineSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
       if(params.getStatus()!=null){
           if(params.getStatus().equals("all")){
               params.setStatus(null);
           }
       }
        return result.success(this.service.findAll(params, current, pageSize));
    }

    @ApiOperation("导入")
    @PostMapping("/importData")
    public Result importData(MultipartFile file) {
        return result.success(this.service.importData(file));
    }

    @ApiOperation("导出")
    @PostMapping("/exportData")
    public Result exportData(@RequestBody TbWmsMaterialReceiptLineSearchParam params) {
        return result.success(this.service.exportData(params));
    }

}
